package com.va.cellinfo;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.widget.TextView;

public class CellInfo extends Activity {

	PhoneStateListener phoneStateListener;
	private TextView content;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		content = (TextView) findViewById(R.id.content);

		int flags = PhoneStateListener.LISTEN_SIGNAL_STRENGTHS |
				PhoneStateListener.LISTEN_CALL_STATE;
		phoneStateListener = new PhoneStateListener() {

			@Override
			public void onCallStateChanged(int state, String incomingNumber) {
				String currentState = "";
				switch(state) {
				case TelephonyManager.CALL_STATE_IDLE:
					currentState = "Phone is idle";
					break;
				case TelephonyManager.CALL_STATE_RINGING:
					currentState = "Phone is ringing";
					break;
				case TelephonyManager.CALL_STATE_OFFHOOK:
					currentState = "Phone is in use 'As a phone'";
					break;
				}
				String text = content.getText().toString();
				content.setText(text + "\n" + currentState);
			}

			@Override
			public void onSignalStrengthsChanged(SignalStrength state) {
				String text = content.getText().toString();
				content.setText(text + "\n" + "signal strength");
			}
		};

		TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
		telephonyManager.listen(phoneStateListener, flags);
	}
}